package bpm.dao.impl.user;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import bpm.dao.user.OrgGroupTypeDao;
import bpm.domain.user.OrgGroupType;
/**
 * 
 * @author ZhaoWangLong Jul 15, 2011
 *
 */
@Repository("orgGroupTypeDao")
public class OrgGroupTypeDaoImpl implements OrgGroupTypeDao {
	@Resource
	private JdbcTemplate jdbcTemplate;
	private Logger logger=Logger.getLogger(OrgGroupTypeDaoImpl.class);
	@SuppressWarnings("unchecked")
	public List<OrgGroupType> findAll() {
		String sql="select ID, NAME from ORG_GROUPTYPE ";
		logger.debug("QuerySQL:"+sql);
		return this.jdbcTemplate.query(sql, new OrgGroupTypeRowMapper());
	}
	@SuppressWarnings("unchecked")
	public OrgGroupType findGroupTypeById(String groupTypeId) {
		String sql="select ID, NAME from ORG_GROUPTYPE where ID =?";
		logger.debug("QuerySQL:"+sql);
		return (OrgGroupType)this.jdbcTemplate.queryForObject(sql, new Object[]{groupTypeId},new OrgGroupTypeRowMapper());
	}
	public void delete(String orgGroupTypeId) {
		String sql="delete from ORG_GROUPTYPE where ID=? ";
		logger.debug("DeleteSQL:"+sql);
		this.jdbcTemplate.update(sql,new Object[]{orgGroupTypeId});
	}
	public void insert(OrgGroupType orgGroupType) {
		String sql="insert into ORG_GROUPTYPE(ID, NAME) values(?,?)";
		logger.debug("InsertSQL:"+sql);
		this.jdbcTemplate.update(sql,new Object[]{orgGroupType.getId(),orgGroupType.getName()});
	}
	public void update(OrgGroupType orgGroupType) {
		String sql="update ORG_GROUPTYPE set NAME=? where ID=?";
		logger.debug("UpdateSQL:"+sql);
		this.jdbcTemplate.update(sql,new Object[]{orgGroupType.getName(),orgGroupType.getId()});
	}

}
